<template>
  <div class="margin-top-sm">
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="ID" width="95">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="用户" align="center">
        <template slot-scope="scope">
          <a :href="scope.row.website" target="_blank" class="color-link">{{
            scope.row.nickname
          }}</a>
        </template>
      </el-table-column>
      <el-table-column label="头像" align="center">
        <template slot-scope="scope">
          <el-image style="width: 50px; height: 50px" :src="scope.row.avatar">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="QQ号码" align="center">
        <template slot-scope="scope">
          {{ scope.row.qq }}
        </template>
      </el-table-column>
      <el-table-column label="邮箱" align="center">
        <template slot-scope="scope">
          {{ scope.row.email }}
        </template>
      </el-table-column>

      <el-table-column label="加入时间" align="center">
        <template slot-scope="scope">
          {{ scope.row.add_time | dateTimeFilter }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="success"
            @click="handleSend(scope.row.id)"
            >发信息</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="margin-top">
      <el-pagination
        @current-change="handlePageChange"
        background
        layout="prev, pager, next"
        :total="count"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { userList } from "@/api/user";
export default {
  data() {
    return {
      list: [],
      formParams: {
        page: 1,
        limit: 10,
      },
      count: 0,
      listLoading: true,
    };
  },
  created() {
    this.handleLoadData();
  },
  methods: {
    // 发消息
    handleSend(id) {
      console.log(id);
    },
    // 加载数据
    handleLoadData() {
      this.listLoading = false;
      userList(this.formParams).then((res) => {
        // console.log(res.data, "list");
        this.count = res.data.count;
        this.list = res.data.data;
      });
    },
    //页数改变
    handlePageChange(index) {
      this.formParams.page = index;
      this.handleLoadData();
    },
  },
};
</script>
